import 'package:drift/drift.dart';

import '../../entity/msg_constant.dart';
import 'act_tb.dart';
import 'base_table.dart';
import 'ses_tb.dart';
import 'user_tb.dart';

/// 消息数据
class MsgTb extends Table with BaseTableMixin {
  @override
  Set<Column> get primaryKey => {id, accountId};

  ///消息id，由外部生成
  IntColumn get id => integer()();

  ///关联登录用户
  TextColumn get accountId => text().references(ActTb, #id)();

  ///消息内容类型
  TextColumn get contentType => textEnum<MsgContentType>()();

  ///消息内容
  TextColumn get content => text().clientDefault(() => '')();

  ///对方是否已读-暂未使用
  BoolColumn get isPeerRead => boolean().clientDefault(() => false)();

  ///自己是否已读-暂未使用
  BoolColumn get isRead => boolean().clientDefault(() => false)();

  ///是否是隐私聊天
  BoolColumn get isPrivateChat => boolean().clientDefault(() => false)();

  ///关联会话表
  TextColumn get sessionId => text().references(SesTb, #id)();

  ///消息状态
  TextColumn get status => textEnum<MsgStatus>()();

  ///关联用户信息
  TextColumn get userId => text().references(UserTb, #id)();

  ///是否置顶
  BoolColumn get isTop => boolean().nullable().clientDefault(() => false)();

  ///发送失败原因
  TextColumn get sendFailReason => text().nullable()();

  ///服务端消息Id
  TextColumn get serviceMsgId => text().nullable()();

  ///服务端消息ID
  TextColumn get serviceNextMsgIds => text().nullable()();

  ///置顶消息服务端id
  IntColumn get pinnedId => integer().nullable()();
}
